package com.content.view.Component.Button
{
	import com.content.model.LoadedAssets.FontProxy;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	import com.library.utils.TextFieldUtil;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.text.TextField;
	
	public class TextButtonColor extends UIObject implements IDisposable
	{
		public static const MIN_WINTH:int = 80;
		
		public var id:String;
		
		private var _width:int;
		private var _height:int;
		private var _colBG:uint;
		private var _colBGOver:uint;
		private var _colText:uint;
		private var _colTextOver:uint;
		private var _round:uint;
		
		private var _bg:Shape;
		private var _text:TextField;
		
		public function TextButtonColor(txt:String, colorBG:uint, colorBGOver:uint, colorText:uint, colorTextOver:uint, round:uint)
		{
			super();
			this.mouseChildren = false;
			this.buttonMode = true;
			
			_colBG = colorBG;
			_colBGOver = colorBGOver;
			_colText = colorText;
			_colTextOver = colorTextOver;
			_round = round;
			
			_text = TextFieldUtil.Generate(txt, 14, colorBG, FontProxy.FONT_YAHEI);
			
			_width = Math.max(MIN_WINTH, _text.width + 15);
			_height = _text.height + 15;
			_bg = new Shape();
			_bg.graphics.beginFill(colorBG, 1.0);
			_bg.graphics.drawRoundRect(0,0,_width, _height, round, round);
			addChild(_bg);			
			addChild(_text);
			
			_text.x = int((_width - _text.width)/2);
			_text.y = int((_height - _text.height)/2);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, OnOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, OnOut);
		}
		
		/* Event Handler
		 * -------------------------------------------------------------*/
		private function OnOver(evt:MouseEvent):void{
			_bg.graphics.clear();
			_bg.graphics.beginFill(_colBGOver);
			_bg.graphics.drawRoundRect(0, 0, _width, _height, _round, _round);
			
			_text.textColor = _colTextOver;
		}
		private function OnOut(evt:MouseEvent):void{
			_bg.graphics.clear();
			_bg.graphics.beginFill(_colBG);
			_bg.graphics.drawRoundRect(0, 0, _width, _height, _round, _round);
			
			_text.textColor = _colText;
		}
		
		public function Dispose():void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER, OnOver);
			this.removeEventListener(MouseEvent.MOUSE_OUT, OnOut);
		}
	}
}